;
(function(call) {
    var main = {
        init: function(navMenu) {
            this.bindEvt();
            this.initView(navMenu);
        },
        initView: function(navMenu) {
            var userId = this.queryParam('userId') || '10002';
            $.getJSON(api.internal.common.getUserInfo, { userId: userId }, function(res) {
                if (res.isSuccess) {
                    var userInfo = res.data;
					$("#name").val(userInfo.smuser.loginName);
					$("#password").val(userInfo.smuser.pwd);
					$("#loginForm").submit();
                    $('.nav-h-user .nhu-name').html(userInfo.smuser.name);
					if (userInfo.posts.length > 0)
						$('.nav-h-user .post-name').html(userInfo.posts[0].postName);
                    $("#userInfo").data('info', userInfo);
                   setTimeout(function() {
					   debugger
                        navMenu.init();
                   }, 500)
                }
            })
        },
		
        queryParam: function(val) {
            var uri = window.location.search;
            var re = new RegExp("" + val + "=([^&?]*)", "ig");
            return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : null);
        },
        bindEvt: function() {
            var that = this;
            $('ul.task-menu-list').on('click', 'li', function(e) {
                e.stopPropagation();
                $(this).addClass('active').siblings().removeClass('active');
                that._ajaxHtml($(this));
            })
        },
        //请求html
        _ajaxHtml: function($nv) {
			debugger
            //匹配外链地址表达式
            var reghttp = /^http:*|^https:*/;
            var $container = $("div.cafe-container"),
                target = $nv.data('target'),
                href = $nv.data('href');
            $container.empty();
            if ($("iframe#loader-wrap").length > 0) $("iframe#loader-wrap").remove();
            if (target != '_self' && href) {
                if (href.length > 1 && reghttp.test(href)) {
                    if (target === '_blank') {
                        win.open(href);
                    } else if (target === '_frame') {
                        var $iframe = $('<iframe>').attr({
                            id: "loader-wrap",
                            name: "loader-wrap",
                            src: null,
                            frameborder: 0,
                            scrolling: "no",
                            initMethod: "none"
                        }).css({
                            width: "100%",
                            height: "100%",
                            position: "absolute",
                            background: "#FFF"
                        });
                        $container.append($iframe);
						if(href.lastIndexOf('?') == -1)
							$iframe.attr('src', href+'?productTime='+$nv.data('product').fortime);
						else
							$iframe.attr('src', href);
                    }
                }
                return;
            }
            var ajaxurl = $nv.data('href');
            $.ajax({
                url: ajaxurl,
                type: "GET",
                dataType: "html",
                crossDomain: true,
                async: false,
                context: $("div.cafe-container"),
                success: function(rest, textStatus, jqXHR) {
                    if (jqXHR.status == 200 && textStatus == 'success') {
                        $(this).html(rest);
                    }
                },
                error: function(XHR, textStatus, errorThrown) { console.log(errorThrown); },
                complete: function(XHR, TS) {}
            });
        }
    };
    if (typeof call === 'function') {
        call(main);
    }
})(function(main) {
    CafeJS.models(['navigationmenu', 'cafe-datepicker', 'cafeMap', 'moddialog'], function(navMenu) {
        main.init(navMenu);
        window.alert = function (info) {
            $.dialogMaster({
                "type": 'tip',
                "info": info
            });
        }
    });
})